#r "PresentationCore"
#r "PresentationFramework"
#r "WindowsBase"
#r "System.Xaml"

using System;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

// WPF 必须 STA
Thread t = new Thread(() =>
{
    // 创建窗口
    var window = new Window
    {
        Title = "Hello WPF CSX",
        Width = 400,
        Height = 300
    };

    // 创建布局
    var stack = new StackPanel();

    // 添加按钮
    var button = new Button
    {
        Content = "Click Me",
        Width = 100,
        Height = 40,
        Margin = new Thickness(20)
    };
    button.Click += (s, e) => MessageBox.Show("Button Clicked!");

    // 添加文本框
    var textbox = new TextBox
    {
        Text = "Hello WPF",
        Margin = new Thickness(20)
    };

    stack.Children.Add(button);
    stack.Children.Add(textbox);

    window.Content = stack;

    // 启动 WPF 窗口
    var app = new Application();
    app.Run(window);

});

t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
